<?php
/**
 * Template Name: create_index
 *
 * @var unknown_type
 */

$siteuri = get_bloginfo ( 'template_url' );
$bloginfo = bloginfo ( "url" );

$smarty = smarty_get_instance ();
global $wpdb;
// get the kouhao
$path = $siteuri . "/kouhao.txt";
$kouhao = file ( $path );
$num = count ( $kouhao );
$id = mt_rand ( 0, $num - 1 );
$text = chop ( $kouhao [$id] );
$posts = getPostByViews ();
$views = "";
foreach ( $posts as $post ) {
	$views .= "<li><a href=\"/?p=" . $post->ID . "\">" . $post->post_title . "</a></li>";

	//                        $views .= "<li>".$i."</li>";
}
query_posts ( 'orderby=date&showposts=5' );
$i = 0;
while ( have_posts () ) :
	the_post ();
	$recommd .= "<li><a href=\"" . get_permalink () . "\">" . get_the_title () . "</a></li>";
endwhile;

$hotsearch = "";
$sql_site = "select keyword from  wp_keyword_stat order by find_count desc limit 0,5;";
$result_site = $wpdb->get_results ( $sql_site );
foreach ( $result_site as $row_site ) {
	$hotsou =  $row_site->keyword;
	$hotsearch .="<li><a href=\"".$bloginfo."?s=".$hotsou."\">$hotsou</a></li>";
}



$smarty->assign ( "kouhao", $text );
$smarty->assign ( "siteurl", $siteuri );
$smarty->assign ( "bloginfo", $bloginfo );
$smarty->assign ( "views", $views );
$smarty->assign ( "recommd", $recommd );
$smarty->assign ( "hotsearch", $hotsearch );
$content = $smarty->fetch ( "index.tpl" );
$fp = fopen ( "/var/www/wp-content/themes/youxisoso/index_content.html", "w" );
echo $fp;
//$fp = fopen ( "D://phpinstall/www/wordpress/wp-content/themes/Beautiful_women/index.html", "w" );
//$fp = fopen ( "D://phpinstall/AppServ/www/wordpress/wp-content/themes/Beautiful_women/index.html", "w" );
fwrite ( $fp, $content );
fclose ( $fp );
?>